package JavaEE_notes.common_API.Thread;

import JavaEE_notes.common_API.Thread.pojo.MyThread;

/**
 * 线程的常用方法
 * @author TaiZai
 * @data 2024/9/24 18:11
 */
public class api_ThreadCommonMethod {
    public static void main(String[] args) throws InterruptedException {
        Thread t1 = new MyThread();
        t1.setName("1号线程");
        t1.start();
        System.out.println(t1.getName());

        Thread t2 = new MyThread("2号线程");
        t2.start();
        t2.join(); // 主线程等待t2线程执行完毕
        System.out.println(t2.getName());

         Thread m = Thread.currentThread();
         m.setName("主线程");
        System.out.println(m.getName());

        for (int i = 0; i < 5; i++) {
            if (i == 3) {
                Thread.sleep(2000); // 让主线程休眠2秒
                break;
            }
            System.out.println(m.getName() + "线程输出了" + i);
        }
    }
}
